package com.datastructure.test.backtreefor;

import java.util.ArrayList;
import java.util.List;

public class BackTreeFor {

    public int[] postorderTraversal (TreeNode root) {
        // write code here
        List<Integer> res = new ArrayList<>();
        doBackFor(res,root);
        int [] result = new int[res.size()];
        for (int i = 0; i < res.size(); i++) {
            result[i]=res.get(i);
        }
        return result;
    }

    public void doBackFor(List<Integer> arr,TreeNode root){
        if(root==null){
            return;
        }
        doBackFor(arr,root.left);
        doBackFor(arr,root.right);
        arr.add(root.val);
    }

}

class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;

    public TreeNode(int val) {
        this.val = val;
    }
}
